<?php include("/includes/header_print_resto.php") ?>
<?php
	$idresto = $_GET['idresto'];
	$bill = $_GET['bill'];

	// SELECTING TAX SERVICE
	$sql_select_tax_service = "SELECT * FROM setting";
	$query_select_tax_service = mysql_query($sql_select_tax_service);
	$data_tax_service = mysql_fetch_array($query_select_tax_service);
	$tax_service = $data_tax_service["tax"]+$data_tax_service["service"];
?>

<h3>Invoice <span style="font-weight: normal; font-size: 10px" class="pull-right"><?php echo date("Y-m-d h:i:s"); ?></span></h3>
<p>Puri Nusa - Lembongan Island - Bali</p>
<p><small>purinusa@hotmail.com +62 366 559 63 72</small></p>
<table>
	<thead>
		<tr>
			<th class="al_left" width="40%">Title</th>
			<th class="al_center" width="20%">Price</th>
			<th class="al_center" width="10%">Qty</th>
			<th class="al_center" width="20%">Amount</th>
		</tr>
	</thead>
	<tbody id="invoice">
		<?php  
			$grand_total = 0;
			$sql_resto_menu = "SELECT * FROM resto_menu WHERE idresto = '$idresto' AND bill = '$bill'";
			$query_resto_menu = mysql_query($sql_resto_menu);
			while ($resto_menu = mysql_fetch_array($query_resto_menu)) {
				$total = $resto_menu['harga'] * $resto_menu['jumlah'];

				$sql_menu = "SELECT * FROM menu WHERE id = '$resto_menu[idmenu]'";
				$query_menu = mysql_query($sql_menu);
				$menu = mysql_fetch_array($query_menu);
		?>
				<tr>
					<td class="al_left"><?php echo $menu['nama']; ?></td>
					<td class="al_right currency" valign="middle"><?php echo $resto_menu['harga']; ?></td>
					<td class="al_right" valign="middle"><?php echo $resto_menu['jumlah']; ?></td>
					<td class="al_right currency" valign="middle"><?php echo $total ?></td>
				</tr>
		<?php 
				$grand_total = $grand_total + $total;
			} 
		?>
	</tbody>
	<tfoot>
		<tr>
			<td class="al_right" colspan="3" valign="middle">
				Total :
			</td>
			<td class="al_right currency" valign="middle" ><?php echo $grand_total; ?></td>
		</tr>
		<tr>
			<td class="al_right" colspan="3" valign="middle">
				Tax & Service :
			</td>
			<td id="tax_service" class="al_right" valign="middle" data-tax="<?php echo $tax_service; ?>"><?php echo $tax_service; ?> %</td>
		</tr>
		<tr>
			<td class="al_right" colspan="3" valign="middle">
				Grand Total :
			</td>
			<td id="grand_total" class="al_right currency" valign="middle"><?php echo ($grand_total+($grand_total*$tax_service/100)); ?></td>
		</tr>
		<?php
			if (!isset($_GET["payment_id"])) {
				switch ($_GET["payment_id"]) {
					case '1':
		?>
		<tr>
			<td class="al_right" colspan="3" valign="middle">
				Payment by Cash :
			</td>
			<td id="grand_total" class="al_right currency" valign="middle"><?php echo $_GET["payment_cash"]; ?></td>
		</tr>
		<tr>
			<td class="al_right" colspan="3" valign="middle">
				Your Change :
			</td>
			<td id="grand_total" class="al_right currency" valign="middle"><?php echo $_GET["payment_cash"] - ($grand_total+($grand_total*$tax_service/100)); ?></td>
		</tr>
		<?php
					break;
				case '2':
		?>
		<tr>
			<td class="al_right" colspan="3" valign="middle">
				Credit Card Charge :
			</td>
			<td id="grand_total" class="al_right" valign="middle"><?php echo $_GET["credit_tax"]; ?> %</td>
		</tr>
		<tr>
			<td class="al_right" colspan="3" valign="middle">
				Full Payment :
			</td>
			<td id="grand_total" class="al_right currency" valign="middle"><?php echo ($grand_total+($grand_total*$tax_service/100)) + (($grand_total+($grand_total*$tax_service/100)) * $_GET["credit_tax"] / 100); ?></td>
		</tr>
		<?php
					break;
				case '3':
		?>
		<tr>
			<td class="al_right" colspan="3" valign="middle">
				Payment by Voucher :
			</td>
			<td id="grand_total" class="al_right currency" valign="middle"><?php echo $_GET["payment_cash"]; ?></td>
		</tr>
		<?php
					break;
				}
			}
		?>
	</tfoot>
</table>
<?php include("/includes/footer_print_resto.php") ?>
<script>
	$(document).ready(function() {
		window.print();
		window.onfocus=function(){ window.close();}
	});
</script>